-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
layout: Always use the largest tag size that fits. #63902
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @zackmdavis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
r? @eddyb |
|
||
// Use the initial field alignment | ||
let mut ity = if def.repr.c() || def.repr.int.is_some() { | ||
let ity = if def.repr.inhibit_enum_layout_opt() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good idea, the old condition here is not about optimizations, it's about whether the discriminant is being forced with #[repr]
.
|
||
for fields in variants.iter() { | ||
let (v_size, v_align) = self.variant_size(fields, &def.repr) | ||
.ok_or(LayoutError::SizeOverflow(ty))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it could be expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also doesn't take field sorting and the offset for the tag into account?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It considers field sorting, but it does not compute it. If sorting happens, all padding can be at the start.
This also means it's relatively cheap.
min_ity | ||
} else { | ||
Integer::for_align(dl, start_align).unwrap_or(min_ity) | ||
Integer::approximate_size(gap).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you pick something large enough to increase the alignment, you'll easily waste space in types containing this one.
If you think this will never happen, that's still not obvious from the code, and you'd have to either compute both and assert they're the same, and we can land that, crater it, etc. or prove it formally somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let gap0
be the original value of gap
. We either have gap = gap0 < align.abi
, or gap = gap0 + (min_ity.size() - gap0).align_to(align.abi) < gap0 + min_ity.size() - gap0 + align.abi = min_ity.size() + align.abi
.
ity.size() <= gap
. In both cases ity.size() <= gap < min_ity.size() + align.abi
, therefore either ity = min_ity
or ity.size() < align.abi
.
@@ -9,7 +9,7 @@ pub enum Align64 { | |||
A(u32), | |||
B(u32), | |||
} | |||
// CHECK: %Align64 = type { [0 x i32], i32, [15 x i32] } | |||
// CHECK: %Align64 = type { [0 x i64], i64, [7 x i64] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you're actually moving the field? How do you know that won't cause the field sorting to produce worse results?
☔ The latest upstream changes (presumably #63998) made this pull request unmergeable. Please resolve the merge conflicts. |
After pull request #63899.
Try to fit the largest integer in the padding bytes before the fields.